package com.yifi.system.controller;

import java.util.List;

import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.yifi.common.SysUtil;
import com.yifi.common.base.BaseController;
import com.yifi.system.domain.SysTreeModel;
import com.yifi.system.service.MisOrgService;
import com.yifi.system.service.SysDeptService;

@Path(value="/sysdept",viewPath = "/")
public class SysDeptController extends BaseController {

	@Inject
	private MisOrgService misOrgService;
	
	@Inject
	private SysDeptService sysDeptService;
	
	public void index()
	{
		render("system/sysdept.html");
	}
	
	public void getOrgTree()
	{
		String c_pro=getPara("c_pro","");
		List<Record> list=misOrgService.getTree("id","name",null,c_pro);
		
		renderJson(list);
	}
	
	public void getOrgDll()
	{
		String sql="select ccode,cname from mis_org where ilayer='2' and bmclass='1' order by ccode ";
		
		List<Record> list=SysUtil.getListDDL(sql, "cname", "ccode", "请选择", "all");
		
		renderJson(list);
	}
	
	public void selectDeptTree()
	{
		String id=getPara("id","");
		String c_pro=getPara("c_pro","");

		List<Record> list=misOrgService.getTree("id","name",null,c_pro);
		
		render("system/sysdept_tree.html");
	}

	public void treeData()
	{
		String sql="select * from mis_org order by isort ";
		
		List<Record> list=Db.find(sql);
        List<SysTreeModel> ztrees = sysDeptService.initZtree(list);
        renderJson(ztrees);
	}
	
}
